<template>
  <div class="elm-edit">
    <elm-page-bb v-loading="loading">
      <elm-flow-pushback-info v-if="page_type=='edit' || page_type=='show'"
                              :nodeins_id="nodeins_id" style="padding: 10px;"></elm-flow-pushback-info>

      <elm-flow-secform ref="secform" :page_type="page_type" :flow_code="flow_code" :nodeins_id="nodeins_id"
                        :data_id="data_id" :upsert_url="upsert_url" @change="setDataID"></elm-flow-secform>

      <template #bottom>
        <elm-flow-submit-button v-if="page_type=='create' || page_type=='edit'"
                                :flow_code="flow_code" :data_id="data_id" :nodeins_id="nodeins_id"
                                @before_submit="v_save" @after_submit="v_save_end">提交</elm-flow-submit-button>
        <elm-flow-pushback-button v-if="page_type=='edit'"
                                  :nodeins_id="nodeins_id" @after_submit="v_save_end">退回</elm-flow-pushback-button>
        <el-button v-if="page_type=='create' || page_type=='edit'" size="small" @click="v_cancle">取消</el-button>
        <el-button v-if="page_type=='template' || page_type=='show'" size="small" @click="v_cancle">返回</el-button>
      </template>
    </elm-page-bb>
  </div>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      loading:true,

      DE_INFO: null,

      page_type: '',//template、create、edit、show

      flow_code: '',

      model: {},
      data_id: '',
      nodeins_id: '',
      upsert_url: '/system/login/flow/FlowsecFormItem_Upsert',

    }
  },
  mounted() {
    this.DE_INFO = elm.dialog.request;

    this.page_type = this.DE_INFO.page_type;
    this.flow_code = this.DE_INFO.flow_code;

    this.upsert_url = this.em(this.DE_INFO.upsert_url)?this.upsert_url:this.DE_INFO.upsert_url;

    if(this.page_type!='template' && this.page_type!='create'){this.data_id = this.DE_INFO.model.id;}
    if(this.page_type=='edit' || this.page_type=='show'){this.nodeins_id = this.model.nodeins_id;}

    this.$nextTick(() => {
      this.v_getData();
    });
  },
  methods: {
    async v_getData(){
      this.$refs["secform"].load(this.endLoading);
    },
    endLoading:function(){this.loading = false;},

    setDataID:function(value){this.data_id=value;},

    async v_save(callback) {
      this.loading = true;
      this.loading = !( this.$refs["secform"].save(callback) );
    },

    v_save_end:function (result){
      if(this.DE_INFO.callVue.v_getData!=null){this.DE_INFO.callVue.v_getData();}
      if(!this.em(this.DE_INFO.table_ref)){this.DE_INFO.callVue.tablebinding('task_running');}
      this.loading = false;
      this.v_cancle();
    },
    v_cancle:function (){
      this.close();//extends: elmVueBase
    },

    em: function (s) {
      if (s == null || s == '') { return true; }
      else { return false; }
    },

  }
}
</script>
<style>
</style>